package com.ruoyi.yl.controller;



import com.ruoyi.common.core.context.SecurityContextHolder;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.yl.common.TestSuccess;
import com.ruoyi.yl.domain.YlChangePrice;
import com.ruoyi.yl.common.Result;
import com.ruoyi.yl.domain.YlDrug;
import com.ruoyi.yl.service.DrugChangePriceService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import static com.ruoyi.yl.constant.YlConstant.*;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * @Author: linKe
 * @Date: 2022/2/17 17:24
 * @FileName: DrugChangePriceManageController
 * @version: 1.0
 * @Description: 调价管理
 */
@RestController
@RequestMapping("/drugManage")
public class DrugChangePriceManageController extends BaseController {

    @Resource
    private DrugChangePriceService drugChangePriceServiceImpl;

    @TestSuccess
    @ApiOperation("查询所有药品信息")
    @GetMapping("/getAllDrug")
    public TableDataInfo getAllDrug(){
        System.out.println(SecurityContextHolder.getUserName());
        startPage();
        List<YlDrug>  allDrug = drugChangePriceServiceImpl.getAllDrug();
        return getDataTable(allDrug);
    }

    @TestSuccess
    @ApiOperation("根据处方类别查药品")
    @GetMapping("/getTypeDrug/{id}")
    public Result<List<YlDrug>> getTypeDrug(@PathVariable("id")Long id){
        List<YlDrug> list = drugChangePriceServiceImpl.getTypeDrug(id);
        return new Result<>(OP_SUCCESS_CODE,OP_SUCCESS_MSG,list);
    }

    @TestSuccess
    @ApiOperation("模糊查询")
    @GetMapping("/getLikeDrug")
    public Result<List<YlDrug>> getLikeDrug(YlDrug dsc){
        List<YlDrug> likeDrug = drugChangePriceServiceImpl.getLikeDrug(dsc);
        return new Result<>(OP_SUCCESS_CODE,OP_SUCCESS_MSG,likeDrug);
    }

    @TestSuccess
    @ApiOperation("根据药品id查调价详情")
    @GetMapping("/getChangePriceByDrugid/{id}")
    public Result<List<YlChangePrice>> getChangePriceByDrugid(@PathVariable("id")Long id){
        List<YlChangePrice> list = drugChangePriceServiceImpl.getChangePriceByDrugid(id);
        return new Result<>(OP_SUCCESS_CODE,OP_SUCCESS_MSG,list);
    }

    /**
     * 没有测试成功
     * @param id
     * @param nowPrice
     * @return
     */
    @ApiOperation("药品调价操作")
    @PutMapping("/updateDrugSalePrice")
        public Result<String> updateDrugSalePrice(Long id, BigDecimal nowPrice){
        drugChangePriceServiceImpl.updateDrugSalePrice(id,nowPrice);
        return new Result<>(OP_SUCCESS_CODE,OP_SUCCESS_MSG,"修改成功");
    }
}